<template>
  <div>
    <h1>房屋信息</h1>
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房屋地址" prop="address">
        <el-input v-model="queryParams.address" placeholder="请输入房屋地址" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="租金" prop="rent">
        <el-input v-model="queryParams.rent" placeholder="请输入租金" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="面积" prop="area">
        <el-input v-model="queryParams.area" placeholder="请输入面积" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" clearable>
          <el-option v-for="dict in house_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="房东" prop="landlordName">
        <el-input v-model="queryParams.landlordName" placeholder="房东姓名" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="租户" prop="tenantName">
        <el-input v-model="queryParams.tenantName" placeholder="租户姓名" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['aiLocation:houses:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate" v-hasPermi="['aiLocation:houses:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['aiLocation:houses:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['aiLocation:houses:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="housesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" prop="id" width="55" />
      <el-table-column label="房屋地址" align="center" prop="address" />
      <el-table-column label="商铺类型" align="center" prop="typeId">
        <template #default="scope">
          <dict-tag :options="shop_type" :value="scope.row.typeId" />
        </template>
      </el-table-column>
      <el-table-column label="租金" align="center" prop="rent" />
      <el-table-column label="面积" align="center" prop="area" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="house_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="房东" align="center" prop="landlord.name" />
      <el-table-column label="租户" align="center" prop="tenant.name" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="头像" align="center" prop="avatarUrl" width="100">
        <template #default="scope">
          <image-preview :src="scope.row.imageUrl" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['aiLocation:houses:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['aiLocation:houses:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, reactive, toRefs } from 'vue';
import { listHouses } from '@/api/houses';

const housesList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  address: null,
  rent: null,
  area: null,
  status: null,
  landlordName: null,
  tenantName: null
});
const house_status = [/* 状态选项数据 */];
const shop_type = [/* 商铺类型数据 */];

function getList() {
  loading.value = true;
  listHouses(queryParams).then(response => {
    housesList.value = response.rows;
    loading.value = false;
  });
}

getList();

// 这里可以定义一些方法，如 handleAdd, handleUpdate, handleDelete, handleQuery, resetQuery
</script>

<style scoped>
/* 添加页面样式 */
</style>
